package com.github.limit.util;

import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;

/**
 * @author: wangdejun
 * @create: 2019-10-17 16:19
 **/
public class BeanUtils {

    public static Class<?> getTargetBean(Object bean) {
        Object object = bean;
        while (AopUtils.isAopProxy(object)) {
            try {
                object = ((Advised) object).getTargetSource().getTarget();
            } catch (Exception e) {
                throw new RuntimeException("get target bean failed", e);
            }
        }
        return object.getClass();
    }

}
